package public

import (
	"context"
	configv1 "devops-super/api/configs/v1"
	v1 "devops-super/api/public/v1"
	"devops-super/internal/consts"
	"devops-super/internal/model/mymodel"
	"devops-super/internal/service"
	"github.com/gogf/gf/v2/util/gconv"
)

func (c *ControllerV1) GetWebMqttInfo(ctx context.Context, req *v1.QcpublicMqttInfoReq) (res *v1.QcpublicMqttInfoRes, err error) {
	res = new(v1.QcpublicMqttInfoRes)
	res, err = service.Aeemqx().GetWebMqttInfo(ctx, req)
	return
}

func (c *ControllerV1) GetSysCustomConfig(ctx context.Context, req *v1.QcpublicSysCustomConfigReq) (res *v1.QcpublicSysCustomConfigRes, err error) {
	res = new(v1.QcpublicSysCustomConfigRes)
	res.Info = &mymodel.SysConfigCustom{}
	configRes, err := service.SysConfig().GetGroupConfigs(ctx, &configv1.GetSysGroupConfigsReq{
		GroupName: consts.SysConfigKeyCustom,
	})
	if err != nil {
		return res, err
	}
	//PlatformName string `json:"platformName"  description:"平台名称"`
	//PlatformAbbr string `json:"platformAbbr"  description:"平台简称"`
	//PlatformLogo string `json:"platformLogo"  description:"平台LOGO"`
	//CopyrightInfo    string `json:"copyrightInfo"  description:"平台版权信息"`
	for _, item := range configRes.Configs {
		if item.ConfigKey == "platformName" {
			res.Info.PlatformName = gconv.String(item.ConfigValue)
		}
		if item.ConfigKey == "platformAbbr" {
			res.Info.PlatformAbbr = gconv.String(item.ConfigValue)
		}
		if item.ConfigKey == "platformLogo" {
			res.Info.PlatformLogo = gconv.String(item.ConfigValue)
		}
		if item.ConfigKey == "copyrightInfo" {
			res.Info.CopyrightInfo = gconv.String(item.ConfigValue)
		}
	}
	return
}
